<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title><%=UserUtil.getCurrentMenuItemName() %></title>
    
    <script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
    
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    	<%if (UserUtil.isBankGroup()) {%>    	
	        $('#findGroupNoImg').click(function() {
				var groupNo = $('#groupNox').val();
				
				if (null != groupNo && 0 != groupNo.length){
					var tmpGroupNo = parseInt(groupNo,10);
					if(! isNaN(tmpGroupNo)){
						$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
						$('#hidden\\.qryGroup\\.groupName').val('');
						$('#qryGroup\\.groupNo').val(groupNo);
						$('#qryGroup\\.groupName').val('');
					}
					else{
						$('#hidden\\.qryGroup\\.groupNo').val('');
						$('#hidden\\.qryGroup\\.groupName').val(groupNo);
						$('#qryGroup\\.groupNo').val('');
						$('#qryGroup\\.groupName').val(groupNo);
						$("#queryGroupResultDiv").html('');
					}
					
					$("#findGroupDiv" ).dialog({  
						title:'帳單業者查詢' 
						, width: 600
						, resizable: true
						, modal: true
					});
					
					$('#doAjaxQueryGroupsBtn').click();
				}
				else{
					$('#hidden\\.qryGroup\\.groupNo').val('');
					$('#hidden\\.qryGroup\\.groupName').val('');
					$('#qryGroup\\.groupNo').val('');
					$('#qryGroup\\.groupName').val('');
					$("#queryGroupResultDiv").html('');
					$("#findGroupDiv" ).dialog({  
						title:'帳單業者查詢' 
						, width: 600
						, resizable: true
						, modal: true
					});
				}
		       });
	        
	        $('#doAjaxQueryGroupsBtn').click(function() {
	            var groupNo = $('#qryGroup\\.groupNo').val();
	            var groupName = $('#qryGroup\\.groupName').val();
	            $("#queryGroupResultDiv").html('');
	
	            $('#hidden\\.qryGroup\\.groupNo').val(groupNo);
	            $('#hidden\\.qryGroup\\.groupName').val(groupName);
	            doQueryGroupAction(1);
	            
	        });
	
	        $('#doAjaxCloseGroupsBtn').click(function() {
	            $("#findGroupDiv" ).dialog( "destroy" );
	        });
        <%}%>
        
        $('#doAddBtn').click(function() {
            waitingDialog({});
            $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
                async : true,
                type : 'POST',
                data : $("#addPayerHiddenFrom").serialize(),
                dataType : 'html',
                success : function(data, textStatus, XMLHttpRequest){
                        $("#payerDiv").html(data);
                        $("#payerDiv" ).dialog({  
                            title:'繳款人資料資料新增' 
                            ,width: 600
                            , resizable: false
                            , modal: true
                        });
                    },
                error : function(XMLHttpRequest, textStatus, errorThrown){
                        $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                        $("#ajaxErrorMessageDiv" ).dialog({  
                            title:'系統錯誤' 
                            ,width: 600
                            , resizable: false
                            , modal: true
                            , buttons: {
                                Ok: function() {
                                    $( this ).dialog( "close" );
                                }
                            }
                        });
                    },
                complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
            });
        });    
        
        $('#doQueryBtn').click(function() {            
            <%if (UserUtil.isBankGroup()) {%>
                 var groupNo = $('#groupNox').val();
                 $('#hidden\\.groupNo').val(groupNo);

            <%}else{%>   
            var groupNo=<%=UserUtil.getUserGroup().getGroupNo() %>;
            
            $('#hidden\\.groupNo').val(groupNo); 
            <%}%>
           // var groupNo = $('#groupNox').val();
            var errMsg = "";
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號是必要欄位<br/>";
			}//2011/06/16 jeff Gu  start   修正    業者代號不存在時 查詢錯誤問題
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}
			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
            
            
            

         
            var payerNo = $('#payerNox').val();

            var payerName = $('#payerNamex').val();
            var houseNo = $('#houseNox').val();
            var payerTelNo = $('#payerTelNox').val();  
            var payerCellNo = $('#payerCellNox').val(); 
            
            $('#hidden\\.payerName').val(payerName);
            $('#hidden\\.houseNo').val(houseNo);
            $('#hidden\\.payerTelNo').val(payerTelNo);
            $('#hidden\\.payerCellNo').val(payerCellNo);
            $('#hidden\\.payerNo').val(payerNo);
            
            doQueryAction(1);
        });           
    }); 
    
    function doQueryAction(pageNumber)
    {
        if (null != pageNumber)
            $('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
        
        $("#queryResultDiv").fadeTo("slow", 0.1);

        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
            async : true,
            type : 'POST',
            data : $("#queryHiddenFrom").serialize(),
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#queryResultDiv").html(data);
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                $("#ajaxErrorMessageDiv" ).dialog({  
                    title:'系統錯誤' 
                    ,width: 600
                    , resizable: false
                    , modal: true
                    , buttons: {
                        Ok: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
                },
            complete: function(XMLHttpRequest, textStatus){
                $("#queryResultDiv").fadeTo("slow", 1);
                closeWaitingDialog();
            }
        });;
    }
    
    function doViewPayerAction(payerPk)
    {
        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
            async : true,
            type : 'POST',
            data : {doAjaxViewPayer: 'doAjaxViewPayer', payerPk: payerPk},
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#payerDiv").html(data);
                    $("#payerDiv" ).dialog({  
                        title:'繳款人資料' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                    });
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                    $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                    $("#ajaxErrorMessageDiv" ).dialog({  
                        title:'系統錯誤' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                        , buttons: {
                            Ok: function() {
                                $( this ).dialog( "close" );
                            }
                        }
                    });
                },
            complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
        });                
    }
    
    function doQueryPayerAction(payerPk)
    {
        $('#hidden\\.payerPk').val(payerPk);

        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
            async : true,
            type : 'POST',
            data : $("#queryPayerHiddenFrom").serialize(),
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#payerDiv").html(data);
                    $("#payerDiv" ).dialog({  
                        title:'繳款人資料修改' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                    });
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                    $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                    $("#ajaxErrorMessageDiv" ).dialog({  
                        title:'系統錯誤' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                        , buttons: {
                            Ok: function() {
                                $( this ).dialog( "close" );
                            }
                        }
                    });
                },
            complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
        });                
    }
    
    function doQueryGroupAction(pageNumber)
    {
        $('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
        $("#queryGroupResultDiv").fadeTo("slow", 0.1);

        waitingDialog({});
        $.ajax({url : "<c:url value='/ajax/Soez1015.action'/>",
            async : true,
            type : 'POST',
            data : $("#queryGroupHiddenFrom").serialize(),
            dataType : 'html',
            success : function(data, textStatus, XMLHttpRequest){
                    $("#queryGroupResultDiv").html(data);
                },
            error : function(XMLHttpRequest, textStatus, errorThrown){
                $("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
                $("#ajaxErrorMessageDiv" ).dialog({  
                    title:'系統錯誤' 
                    ,width: 600
                    , resizable: false
                    , modal: true
                    , buttons: {
                        Ok: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                });
                },
            complete: function(XMLHttpRequest, textStatus){
                if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
                    $("#findGroupDiv" ).dialog( "close" );
                    $("#findGroupDiv" ).dialog( "open" );                   
                }
                closeWaitingDialog();
                $("#queryGroupResultDiv").fadeTo("slow", 1);
            }
        });
    }    
    //-->
    </script>
</head>
<body>
<div id="mainAreaCT">
        <jsp:include page="/includes/path.jsp"/>
        <jsp:include page="/includes/subMenu.jsp"/>
        
    <div id="payerFormDiv">
        <stripes:form id="payerFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" method="post">
                 
            <table id="queryForm">
                <%  if (UserUtil.isBankGroup()) {%>
                <tr>
	                <th>業者代號<span id="mustKeyInStar">**</span></th>
	                <td colspan="3">
	                    <div id="findGroupNoImg"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
	                        <input id="groupNox" maxlength="12" name="groupNo" type="text" size="12" />                              
	                	<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryGroup.groupName }"/></span>	               
	                </td>                
                </tr>
		        <% 
		            }
		        %> 
				<tr>
                    <th>客戶編號</th>
                    <td>
                        <stripes:text id="payerNox" name="payerNo" size="15" maxlength="20" />
                    </td> 
                    <th>姓名</th>
                    <td>
                        <stripes:text id="payerNamex" name="payerName" size="15" maxlength="20" />
                    </td>                 
                </tr>  
                <tr>
                    <th>電話</th>
                    <td>
                        <stripes:text id="payerTelNox" name="payerTelNo" size="15" maxlength="20" />
                    </td>
                    <th>手機</th>
                    <td>
                        <stripes:text id="payerCellNox" name="payerCellNo" size="15" maxlength="10" />
                    </td>                    
                </tr>              
                <tr>
                    <th>門牌號碼</th>
                    <td colspan="3">
                        <stripes:text id="houseNox" name="houseNo" size="30" maxlength="30" />
                    </td>                    
                </tr>          
                <tr>
                    <td colspan="4" class="queryFunction">
                        <stripes:button id="doQueryBtn" name="doQueryBtn" value="查詢" class="formBtn"/>
                        <stripes:button id="doAddBtn" name="doAddBtn" value="新增" class="formBtn"/>
                    </td>
                </tr>
            </table>
        </stripes:form>
    </div> 
    
    <!-- 繳款人查詢結果  -->
    <div id="queryResultDiv" style="display: none;">
    </div>    
    <div id="queryHiddenFormDiv" style="display: none;">
        <stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
            method="post" onsubmit="javascript: return false;">
            <stripes:hidden id="hidden.groupNo" name="groupNo" />
            <stripes:hidden id="hidden.payerNo" name="payerNo" />
            <stripes:hidden id="hidden.payerName" name="payerName" />
            <stripes:hidden id="hidden.houseNo" name="houseNo"/>
            <stripes:hidden id="hidden.payerTelNo" name="payerTelNo"/>
            <stripes:hidden id="hidden.payerCellNo" name="payerCellNo"/>
            <stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />         
                        
            <input type="hidden" id="method1" name="doAjaxQuery"/>
        </stripes:form>
    </div>   
    
    <!-- 繳款人明細查詢 -->
    <div id="payerDiv" style="display: none;">
    </div>
    <div id="queryPayerHiddenFormDiv" style="display: none; ">
        <stripes:form id="queryPayerHiddenFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
            method="post" onsubmit="javascript: return false;">         
            <stripes:hidden id="hidden.payerPk" name="payerPk"/>       
            <input type="hidden" id="method2" name="doAjaxQueryPayer"/>
        </stripes:form>
    </div>    
    
    <div id="addPayerHiddenFormDiv" style="display: none; ">
        <stripes:form id="addPayerHiddenFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
            method="post" onsubmit="javascript: return false;">                
            <input type="hidden" id="method3" name="doAjaxAddPayer"/>
        </stripes:form>
    </div> 
            
    <!-- 業者代號 查詢 -->
    <div id="findGroupDiv" style="display: none;">
        <div id="queryGroupDiv">
        <table>
            <tr>
                <th>業者代號</th>
                <td><input id="qryGroup.groupNo" type="text" size="12" maxlength="12" /> </td>
            </tr>
            <tr>
                <th>名稱</th>
                <td><input id="qryGroup.groupName" type="text" size="20" /></td>
            </tr>
            <tr>
                <td colspan="2" class="queryFunction">
                    <input type="button" value="查詢" id="doAjaxQueryGroupsBtn"/>
                    <input type="button" value="離開" id="doAjaxCloseGroupsBtn"/>
                </td>
            </tr>
        </table>
        </div>
        <div id="queryGroupResultDiv" style="display: none;">
        </div>
    </div>
    
    <div id="queryGroupHiddenFormDiv" style="display: none; ">
        <stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
            method="post" onsubmit="javascript: return false;">
            <stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName"/>
            <stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo"/>
            <stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />           
            <input type="hidden" id="method" name="doAjaxQueryGroups"/>
        </stripes:form>
    </div> 
     <!-- 業者代號 查詢 -->
        <div id="findGroupDiv1" style="display: none;">
            <div id="queryGroupDiv">
            <table>
                <tr>
                    <th>業者代號</th>
                    <td><input id="qryGroup.groupNo1" type="text" size="12" maxlength="12" /> </td>
                </tr>
                <tr>
                    <th>名稱</th>
                    <td><input id="qryGroup.groupName1" type="text" size="20" /></td>
                </tr>
                <tr>
                    <td colspan="2" class="queryFunction">
                        <input type="button" value="查詢" id="doAjaxQueryGroupsBtn1"/>
                        <input type="button" value="離開" id="doAjaxCloseGroupsBtn1"/>
                    </td>
                </tr>
            </table>
            </div>
            <div id="queryGroupResultDiv1" style="display: none;">
            </div>
        </div>
        
        <div id="queryGroupHiddenFormDiv1" style="display: none; ">
            <stripes:form id="queryGroupHiddenFrom1" beanclass="com.feib.soeasy.action.Soez1015ActionBean" 
                method="post" onsubmit="javascript: return false;">
                <stripes:hidden id="hidden.qryGroup.groupName1" name="qryGroup.groupName"/>
                <stripes:hidden id="hidden.qryGroup.groupNo1" name="qryGroup.groupNo"/>
                <stripes:hidden id="hidden.queryGroupResult.pageNumber1" name="queryGroupResult.pageNumber" />           
                <input type="hidden" id="method" name="doAjaxQueryGroups1"/>
            </stripes:form>
        </div>           
        
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>       
</div>
</body>
</html>
